<template>
	<view>
		<!-- <view class="title">
			<view :class="stu==1?'tab1 active':'tab1'" @click="changeTab(1)">
				企业注册1
				<view class="line" v-show="stu==1"></view>
			</view>
			<view :class="stu==2?'tab1 active':'tab1'" @click="changeTab(2)">
				供应商
				<view class="line" v-show="stu==2"></view>
			</view>
		</view> -->
		<view class="contentBox">
			<view class="box1" v-show="stu==1">
				<view class="input-p">
					<view class="">
						<text>手机号</text>
						<input class="getnum" type="text" v-model="account" placeholder="请填写您的手机号"/>
						<view class="getyzm" @click="sendCode" v-if="!sendCodeStu">获取验证码</view>
						<view class="getyzm" v-if="sendCodeStu">{{time}}秒后获取</view>
					</view>
					<view class=""><text>验证码</text><input type="text" v-model="code" placeholder="请填写验证码"/></view>
					<view class=""><text>密码</text><input password="true" v-model="password" placeholder="请填写密码"/></view>
				</view>
				<button class="login" @click="doRegister">确定</button>
			</view>
			<!-- <view class="box1" v-show="stu==2">
				<view class="input-p">
					<view class="">
						<text>手机号</text>
						<input class="getnum" type="text" v-model="account" placeholder="请填写您的手机号"/>
						<view class="getyzm" @click="sendCode">获取验证码</view>
					</view>
					<view class=""><text>验证码</text><input type="text" v-model="code" placeholder="请填写验证码"/></view>
					<view class=""><text>密码</text><input password="true"  v-model="password" placeholder="请填写密码"/></view>
				</view>
				<button class="login" @click="doRegister">确定</button>
			</view> -->
		</view>
	</view>
</template>
<script>
	import API from '../../common/api.js';
	export default {
		data() {
			return {
				stu:true,
				uType:1,//用户类型  1-企业用户  2-供应商
				account:'',//手机号
				password:'',//密码
				code:'',//验证码
				sendCodeStu:false,
				time:60
			}
		},
		methods: {
			changeTab(stu1){
				this.stu=stu1;
				this.account='';
				this.password='';
				this.code='';
			},
			doRegister(){
				if(this.account&&this.password&&this.code){
					var _this = this;
					uni.request({
						url:API.updatePassword,
						data:{
							account:_this.account,
							password:_this.password,
							code:_this.code
						},
						method:"POST",
						header:API.get_head(),
						success: (res) => {
							if(res.data.success){
								uni.navigateBack({
									delta:1,
								})
							}
							uni.showToast({
								title:res.data.message,
								icon:"none"
							})
						},
						fail: () => {
							uni.showToast({
								title:"加载失败",
								icon:'none'
							})
						}
					})
				}else{
					uni.showToast({
						title:"请完整填写",
						icon:"none"
					})
				}
			},
			sendCode(){
				var _this = this;
				if(!this.checkPhone()){return false}
				
				_this.sendCodeStu = true
				var T= setInterval(function(){
					_this.time --
					if(_this.time==0){
						 _this.time = 60
						 _this.sendCodeStu = false
						 clearInterval(T)
					}
				},1000)
				
				uni.request({
					url:API.sendCode,
					data:{tel:_this.account},
					method:"POST",
					header:API.get_head(),
					success: (res) => {
						uni.showToast({
							title:res.data.message,
							icon:"none"
						})
					},
					fail: () => {
						uni.showToast({
							title:"加载失败",
							icon:'none'
						})
					}
				})
			},
			checkPhone(){
				if(!(/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(this.account))){ 
					uni.showToast({
						title:"手机号码错误",
						icon:"none"
					})
					return false; 
				}
				return true; 
			}
		}
	}
</script>

<style>
	page{background:#FFFFFF;}
	.title{overflow:hidden;}
	.tab1{float: left;height:87upx;line-height:87upx;width:50%;border-bottom:1upx solid #e9e9e9;position:relative;text-align: center;font-size:34upx;color:#666666;}
	.active{color:#067aee;}
	.line{width:100%;height:4upx;background:#067aee;position:absolute;bottom: 0;}
	.box1{margin-top:76upx;}
	.input-p>view{
		display:flex;
		font-size:30upx;
		font-weight:bold;
		border-bottom:1px solid #e5e5e5;
		padding:45upx 60upx;
	}
	.input-p>view>text{
		display:block;
		width:90upx;
		padding-right:30upx;
		line-height:55upx;
		color:#292929;
	}
	.input-p>view>input{
		width:510upx;
		vertical-align: middle;
		font-weight:normal;
	}
	.input-p>view>.getnum{
		width:330upx;
	}
	.login{
		margin:0 60upx;
		height:88upx;
		background:#067aee;
		color:#fff;
		margin-top:140upx;
		font-size:34upx;
		border-radius:4upx;
	}
	.getyzm{
		float:left;
		border:1upx solid #e7e7e7;
		line-height:1;
		color:#666666;
		padding:19upx;
	}
	
	
	
	
	.swiper-tab-list {
		display: inline-block;
	}
	/* #ifdef MP-ALIPAY */
	.swiper-tab-list {
		display: inline-block;
	}
	/* #endif */
</style>
